***********************************************************************
*Replication Code of Article Bargsted & Kedar, AJPS (Forthcomming)   **Code creates variables and modifies structure of data for           *
*conditional logistic analysis                                       *  
*Languaje: STATA                                                     *
*Imput file: isr06.dta                                               *
*                                                                    *
*DATA: Israel 2006 election study                                    ***download data at: www.ines.tau.ac.il                               *     
*Code Authors: Matias Bargsted & Orit Kedar                          ***********************************************************************

*version 9.0

set mem 64m

use "C:\Users\ibh4\Desktop\Replication File\new2006.dta" 
/* use "C:\Documents and Settings\bargsted\My Documents\Paper Coalition Voting\Israel\isr06.dta"*/

rename b7 self
rename b11 lik					/*likud*/
rename b13 lab 					/*labor*/
rename b15 kad					/*kadima*/
rename b17 sha					/*shas*/
rename b19 maf					/*haichud haleumi - mafdal*/
rename b21 isr					/*israel beitenu*/
rename b23 mer					/*meretz*/

gen dislik=abs(self-lik)
gen dislab=abs(self-lab)
gen diskad=abs(self-kad)
gen dissha=abs(self-sha)
gen dismaf=abs(self-maf)
gen disisr=abs(self-isr)
gen dismer=abs(self-mer)

gen vote=.				/*these are ordered left to right, prevote variable*/
replace vote=1 if b73==8 		/*meretz*/
replace vote=2 if b73==3		/*labor*/
replace vote=3 if b73==1		/*kadima*/
replace vote=4 if b73==7		/*shas*/
replace vote=5 if b73==2		/*likud*/
replace vote=6 if b73==4		/*israel beitenu*/
replace vote=7 if b73==5		/*ichud leumi - mafdal*/

gen selfmer=self if vote==1 		/*self placement by meretz voters*/
gen selflab=self if vote==2 		/*self placement by labor voters*/
gen selfkad=self if vote==3
gen selfsha=self if vote==4 
gen selflik=self if vote==5 	
gen selfisr=self if vote==6 	
gen selfmaf=self if vote==7 	

gen pmer=mer if vote==1			/*perception of placement of meretz by meretz voters*/
gen plab=lab if vote==2	    		/*perception of placement of labor by labor voters*/
gen pkad=kad if vote==3
gen psha=sha if vote==4	
gen plik=lik if vote==5	
gen pisr=isr if vote==6	
gen pmaf=maf if vote==7	

drop if vote==.				/*this paragraph is for a figure of voter and party placements*/

rename b75 cokad
rename b78 colab
rename b81 colik

rename b87 mkkad
rename b89 mklab
rename b91 mklik

gen codir=colik-colab			/*key explanator: chances of a left (-) or right-leaning (+) coal. */

/*coding of coalitions the reposndent prefers to left (-1) center(0) and right (1)*/
gen prefr=.
replace prefr=1 if c34==28 | c34==29 | c34==31 | c34==36 |c34==39
replace prefr=-1 if c34==27 | c34==30 | c34==32 | c34==40
replace prefr=0 if c34==33 | c34==38 | c34==41 | c34==37

gen self2=self
recode self2 (0 1 2=1) (3 4=2) (5=3) (6 7=4) (8 9 10=5)
tab vote self2 if codir<0, col
tab vote self2 if codir>0, col

gen coal=.
replace coal=-2 if codir<0
/*replace coal=-1 if codir<0 & codir>=-50;
replace coal=1 if codir>0 & codir<=50;*/
replace coal=2 if codir>0

tab coal self, col
tab vote self2,col 
tab vote self2 if prefr==1, col 
tab vote self2 if prefr==-1, col

/*CODING OF VARIABLES FOR MULTIVARIATE ANALYSIS*/

gen dense=.							/* density of living in household is a good predictor of class in Israel*/
replace dense= c84/c82
gen arab=0							/*arab*/
replace arab=1 if c93==2
gen rus=0								
replace rus=1 if c62==1						/* Immigrated from the FSU 1989 or later */
rename c54 age 							/* age */
rename c56 relig						/* religiosity - behavioral */
rename c89 fem							/* gender: 1=fem, 0=male */
recode fem (1=0)(2=1)
rename c75 edu							/* formal education in years */
replace edu=20 if edu>20

/*ethnicity, zabar as reference category*/

/*rename moz_cat moz
gen miz=0							/* mizrahi */
replace miz=1 if moz==1 | moz==2 | moz==7 | moz==8
gen ash=0							/* ashkenazi */
replace ash=1 if (moz==3 | moz==4 | moz==5 | moz==9 | moz==10 | moz==11) & rus~=1 */
gen fsu=0
replace fsu=1 if rus==1


/*positions on church state*/
rename a44 relpos
replace relpos=. if relpos>4
recode relpos (1=4) (2=3) (3=2) (4=1)

/*positions on organized economy*/
rename a45 ecopos
replace ecopos=. if ecopos>4

/*positions on territorial compromise*/
rename a15 terpos

/*Ideological Extreminism*/
gen ideo = self
recode ideo 0/1=1 2/4=2 5=3 6/8=4 9/10=5

/*Political Knowledge*/
gen pknow6=c51
recode pknow6 (1=1) (*=0)
gen pknow7=c52
recode pknow7 (2=1) (*=0)
gen pknow8=c53
recode pknow8 (1=1) (*=0)
gen pknow = pknow6+pknow7+pknow8

/*Political Extremism*/
gen extreme =.
replace extreme=1 if self==5
replace extreme=2 if self==4 | self==6
replace extreme=3 if self==3 | self==7
replace extreme=4 if self==2 | self==8
replace extreme=5 if self==1 | self==9
replace extreme=6 if self==0 | self==10

/*Party Identification*/
gen pid=1 if a59>=8 | a60>=8 | a61>=8 | a62>=8 | a63>=8 | a64>=8 | a65>=8 
recode pid .=0
recode pid 1=2 if a59>=9 | a60>=9 | a61>=9 | a62>=9 | a63>=9 | a64>=9 | a65>=9 
recode pid 1/2=3 if a59==10 | a60==10 | a61==10 | a62==10 | a63==10 | a64==10 | a65==10 

/*Interactions*/
gen pidcod=pid*codir
gen pknow_codir =pknow*codir
gen pid_pknow=pknow*pid
gen pknow_pid_codir=pknow*pid*codir
gen codir_extre=codir*extre


*Expand Data set for Clogit Analysis

/* create and id variable */
gen count=_n
gen seven=7
expand seven
sort count

/*create a one through seven variable */
gen os=.
replace os=1 if count!=count[_n-1]
replace os=2 if os[_n-1]==1
replace os=3 if os[_n-1]==2
replace os=4 if os[_n-1]==3
replace os=5 if os[_n-1]==4
replace os=6 if os[_n-1]==5
replace os=7 if os[_n-1]==6
sum os

/*turn vote cvhoice into J-1 dummies */
gen choice=.
replace choice=1 if vote==os
replace choice=0 if vote~=os & vote~=.

/*general coefs (ij) */
/*distances between voters and parties */

gen dis=.
replace dis=(self-mer)^2 if os==1
replace dis=(self-lab)^2 if os==2
replace dis=(self-kad)^2 if os==3
replace dis=(self-sha)^2 if os==4
replace dis=(self-lik)^2 if os==5
replace dis=(self-isr)^2 if os==6
replace dis=(self-maf)^2 if os==7

/*party-specific coefficients */

gen cmer=0
replace cmer=1 if os==1
gen clab=0
replace clab=1 if os==2
gen ckad=0
replace ckad=1 if os==3
gen csha=0
replace csha=1 if os==4
gen clik=0
replace clik=1 if os==5
gen cisr=0
replace cisr=1 if os==6
gen cmaf=0
replace cmaf=1 if os==7

gen parmer=0
replace parmer=1 if os==1
gen parlab=0
replace parlab=1 if os==2
gen parkad=0
replace parkad=1 if os==3
gen parsha=0		
replace parsha=1 if os==4
gen parlik=0		
replace parlik=1 if os==5
gen parisr=0		
replace parisr=1 if os==6
gen parmaf=0		
replace parmaf=1 if os==7

****Create Independent Variables
rename c80 inc 								
recode inc (1=5) (2=4) (3=3) (4=2) (5=1)

local party mer lab kad sha lik isr maf 
	foreach e of local party {
		gen `e'codir=codir*par`e'
		gen `e'dense=dense*par`e'
		gen `e'arab=arab*par`e'
		gen `e'rus=rus*par`e'
		gen `e'age=age*par`e'
		gen `e'relig=relig*par`e'
		gen `e'fem=fem*par`e'
		gen `e'edu=edu*par`e'
		gen `e'inc=inc*par`e'
		gen `e'prefr=prefr*par`e'
		gen `e'fsu=fsu*par`e'
		gen `e'relpos=relpos*par`e'
		gen `e'ecopos=ecopos*par`e'
		gen `e'terpos=terpos*par`e'
		gen `e'pid=pid*par`e'
		gen `e'extre=extreme*par`e'
		gen `e'ideo=ideo*par`e'
		gen `e'self=self*par`e'
		gen `e'self2=self*self*par`e'
               	gen `e'selfco=self*codir*par`e'
            	gen `e'self2co=self*self*codir*par`e' 
		gen `e'xtcod=extreme*codir*par`e'
		gen `e'pidcod=pid*codir*par`e'
		gen `e'pknow=pknow*par`e'
		gen `e'pknowcod=pknow*codir*par`e'
		gen `e'pidpknow=pknow*pid*par`e'	
		gen `e'pidpknowcod=pknow_codir*pid*par`e'	
	}
